package com.datawin.taotaocheche.ui.fragment.biz;

import java.util.List;
import java.util.Map;

import com.datawin.taotaocheche.base.BaseBiz;
import com.datawin.taotaocheche.base.BaseResp;
import com.datawin.taotaocheche.bean.UserInfo;
import com.datawin.taotaocheche.comm.BaseSubscribe2;
import com.datawin.taotaocheche.comm.RetrofitHelp;

import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by chenjian on 17/11/30.
 */

public class MineBiz  extends BaseBiz{


    /**
     * 获取banner图
     *
     * @param
     * @param callback
     */
    public void getUserInfo(String  token, final BaseBiz.Callback<List<UserInfo>> callback) {
        com.add(RetrofitHelp.getSecretApi().userInfoPage(token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe2<BaseResp<List<UserInfo>>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((List<UserInfo>)obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((List<UserInfo>)obj);
                    }
                })
        );
    }


    /**
     * 上传头像
     *
     * @param
     * @param callback
     */
    public void updateImg(Map<String, RequestBody> map, List<MultipartBody.Part> parts, final BaseBiz.Callback<Object> callback) {
        com.add(RetrofitHelp.getSecretApi().updatePhoto(map, parts)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe2<BaseResp<Object>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((Object) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((Object) obj);
                    }
                })
        );
    }
}
